/*var mongoose=require('mongoose');
 var config=require('../config');
 var mongodb = require('mongodb');*/
var mongoose = require('./mongoConn');
var Schema = mongoose.Schema;

var userBoxSchema = new Schema({
    buyer_id: String,
    box_id: String
});

var UserBox = mongoose.model("UserBox", userBoxSchema);

UserBox.prototype.findUserById = function (boxid, callback) {
    UserBox.findOne({box_id: boxid}, function (err, datas) {
        return callback(datas);
    });
}

UserBox.prototype.findIdByUser = function (id, callback) {
    UserBox.find({buyer_id: id}, function (err, datas) {
        return callback(datas);
    });
}

UserBox.prototype.findIdsByUser = function (id, callback) {
    UserBox.find({buyer_id: id}, {box_id: 1}, function (err, datas) {
        return callback(datas);
    });
}

UserBox.prototype.removeUserById = function (boxid, callback) {
    UserBox.remove({box_id: boxid}, function (err) {
        return callback(err);
    });
}

UserBox.prototype.saveUserById = function (boxid, buyerid, callback) {
    UserBox.save({box_id: boxid}, {buyer_id: buyerid}, function (err) {
        return callback(err);
    })
}


module.exports = UserBox;